package com.fr.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;
import org.apache.commons.dbutils.ResultSetHandler;
import com.fr.model.ServiceType;

public class ServiceTypeDao extends BaseDao{
	public List<ServiceType> getAll() {
		try {
			String sql = "select id, icon, title "
					+ " from servicetype"
					+ " order by id";
			return queryRunner.query(sql, new ResultSetHandler<List<ServiceType>>() {
				@Override
				public List<ServiceType> handle(ResultSet rs) throws SQLException {
					List<ServiceType> serviceTypes = new LinkedList<ServiceType>();
					while(rs.next()) {
						serviceTypes.add(
							new ServiceType(
									rs.getInt("id"),
									rs.getString("icon"),
									rs.getString("title"))
						);
					}
					return serviceTypes;
				}
			});
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
}